package com.example.makerspace;
import org.springframework.util.ResourceUtils;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
public class test03 {
        private URL url = null; // 音乐文件的URl
        private AudioStream audioStream = null; // 播放器
        public test03() {
            try {
                File file = ResourceUtils.getFile("classpath:templates/skype.wav");
                url = file.toURI().toURL();
                InputStream inputStream = url.openStream(); // 获得音乐文件的输入流
                audioStream = new AudioStream(inputStream);
                System.out.println(url);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        /**
         * 用AudioPlayer静态成员player.start播放音乐
         */
        public void play() {
            AudioPlayer.player.start(audioStream);
        }

        public static void main(String[] args) {
            new test03().play();
        }
    }
